class Competition
  include Mongoid::Document
  include Mongoid::Timestamps::Created

  field :name, type: String
  field :url, type: String
  field :description, type: String
  
  has_many :topics, dependent: :destroy, as: :topic_container
  has_many :question_lists, dependent: :destroy
  has_many :tasks, dependent: :destroy

  has_many :sections, dependent: :destroy

  def to_param
    self.url
  end

  before_save do |doc|
    doc.url = doc.name if doc.url.nil?
  end
end
